package com.qzsoft.zhjd.monitoring.modules.videogroup.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.qzsoft.jeemis.common.utils.Result;
import com.qzsoft.jeemis.common.validator.ValidatorUtils;
import com.qzsoft.jeemis.common.validator.group.AddGroup;
import com.qzsoft.jeemis.common.validator.group.UpdateGroup;
import com.qzsoft.zhjd.common.utils.ResultUtils;
import com.qzsoft.zhjd.monitoring.modules.videogroup.dto.VideoGroupTreeDto;
import com.qzsoft.zhjd.monitoring.modules.videogroup.entity.VideoGroupEntity;
import com.qzsoft.zhjd.monitoring.modules.videogroup.service.VideoGroupService;

/**
 * @ClassName VideoGroupController
 * @Description 视频分组控制器
 * @author linhuawei
 * @since 2022-03-24
 */
@RestController
@RequestMapping("/api/videoGroup")
public class VideoGroupController {

    @Autowired
    private VideoGroupService videoGroupService;

    /**
     * @Title tree
     * @Description 获取视频监控左侧树
     * @return 视频监控左侧树
     */
    @GetMapping("/tree")
    public Result<List<VideoGroupTreeDto>> tree() {
        List<VideoGroupTreeDto> data = videoGroupService.tree();
        return ResultUtils.ok(data);
    }

    /**
     * @Title save
     * @Description 添加分组
     * @param entity 分组对象
     * @return 添加结果
     */
    @PostMapping("/save")
    public Result<VideoGroupEntity> save(@RequestBody VideoGroupEntity entity) {
        ValidatorUtils.validateEntity(entity, AddGroup.class);
        videoGroupService.save(entity);
        return ResultUtils.ok(entity);
    }

    /**
     * @Title update
     * @Description 修改分组
     * @param entity 分组对象
     * @return 修改结果
     */
    @PostMapping("/update")
    public Result<String> update(@RequestBody VideoGroupEntity entity) {
        ValidatorUtils.validateEntity(entity, UpdateGroup.class);
        videoGroupService.updateById(entity);
        return ResultUtils.ok();
    }

    /**
     * @Title delete
     * @Description 删除分组
     * @param id 分组主键
     * @return 删除结果
     */
    @PostMapping("/delete/{id}")
    public Result<String> delete(@PathVariable("id") String id) {
        videoGroupService.removeById(id);
        return ResultUtils.ok();
    }

}
